package com.episode4;

import static com.util.HtmlStringUtil.getFooterHtml;
import static com.util.HtmlStringUtil.getHeaderHtml;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HelloServlet
 */
public class IncludeServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	public static final String EPISODE = "episode4";

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
	
		// response တွင် ယူနီကုဒ် Encoding အဖြစ် သတ်မှတ်ခြင်း
		response.setCharacterEncoding("UTF-8");
		PrintWriter writer = response.getWriter();
		writer.println(getHeaderHtml(EPISODE, "Include ကို စမ်းသပ်ရေးသားခြင်း"));
		
		// RequestDispatcher ကို HttpServletRequest မှ ခေါ်ယူခြင်း
		RequestDispatcher disp = request.getRequestDispatcher("/ToInclude");
		// Dispatcher မှ Servlet ကို ခေါ်ယူ အလုပ်လုပ်စေခြင်း
		disp.include(request, response);
		
		writer.println(getFooterHtml());		
	}

}
